package com.foreknow.demo9;

public class UserManager {
    String[] name = new String[2];
    String[] pass = new String[2];

    public void register(String username,String password) throws CustomException{
        //查看字符串String的长度
        int nLength = username.length();
        int npass = password.length();
        //验证用户名和密码是否为空
        if(username.equals("")|| password.equals("")) {
            throw new CustomException("输入的用户和密码为空");
        }
        //验证用户名的长度
        if(nLength < 6 || nLength > 14) {
            throw new CustomException("用户的长度不符合长度");
        }

        //验证密码的长度
        if(npass < 8 || npass > 16) {
            throw new CustomException("密码的长度不符合长度");
        }

        for(int i = 0;i<name.length;i++) {
            if(name[i] == null && pass[i] == null) {
                name[i] = username;
                pass[i] = password;
                System.out.println("注册成功了......");
                return;  //方法中遇到return,方法就结束了
            }
        }
        throw new CustomException("用户已经达到上限，无法注册了");
    }

    public static void main(String[] args) {
        UserManager manager = new UserManager();
        try {
            manager.register("tom","123456");
        } catch (CustomException e) {
            e.printStackTrace();
        }
        System.out.println("11111111111111111111111111111111111111111");
    }
}
